package com.zlx.exchange.authority.role.controller;


import com.zlx.exchange.authority.role.service.RoleService;
import com.zlx.exchange.domain.entity.Role;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Role)表控制层
 *
 * @author makejava
 * @since 2023-09-04 21:21:00
 */
@RestController
@RequestMapping("role")
public class RoleController {
    /**
     * 服务对象
     */
    @Resource
    private RoleService roleService;

    /**
     * 分页查询
     *
     * @param role    筛选条件
     * @param pageNum 查询页数
     * @param pageNum 查询总页数
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<?> queryByPage(Role role, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return this.roleService.queryByPage(role, pageNum, pageSize);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<?> queryById(@PathVariable("id") Integer id) {
        return this.roleService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param role 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<?> add(Role role) {
        return this.roleService.insert(role);
    }

    /**
     * 编辑数据
     *
     * @param role 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<?> edit(Role role) {
        return this.roleService.update(role);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<?> deleteById(Integer id) {
        return this.roleService.deleteById(id);
    }

}

